//
// Created by vivi on 14/04/2018.
//

#pragma once
#include "./collisionobj.h"
#include "VPly/vply.h"

namespace HairEngine {
	class UniformGridCollisionObject: public CollisionObject {
	Public:
		UniformGridCollisionObject(const Eigen::Affine3f & transform):
				CollisionObject(transform) {}

		UniformGridCollisionObject(const Eigen::Affine3f & transform, const Eigen::Affine3f & previousTransform, const float t):
				CollisionObject(transform, previousTransform, t) {}

		Eigen::AlignedBox3f boundingBox() const override {
			return Eigen::AlignedBox3f(Eigen::Vector3f(-1.0f, 0.0f, -1.0f), Eigen::Vector3f(1.0f, 0.0f, 1.0f)); //xz plane
		}

		//We use a inifinity plane solution for similification
		float modelDistance(const Eigen::Vector3f & modelPos, Eigen::Vector3f *outGradientPtr = nullptr) const override  {
			if (outGradientPtr)
				*outGradientPtr = Eigen::Vector3f::UnitY();
			return modelPos.y();
		}

		std::ostream & vplyStream(std::ostream & os) const override {
			VPly::writeUniformGrid(
					os,
					EigenUtility::toVPlyMatrix4f(localToWorldTransform.matrix()),
					VPly::VPlyIntAttr("type", VPlyOptions::CollisionObject_)
			);
			return os;
		}
	};
}

